﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace GameWP
{
    public class HpBar : Sprite2D
    {
    #region Properties
        public float PositionX
        {
            set { _position.X = value; }
        }

        protected int _hp;
        public int Hp
        {
            get { return _hp; }
            set { _hp = value; }
        }

        protected Color _color;
        public Color Color
        {
            get { return _color; }
            set { _color = value; }
        }

        protected int _maxhp;
        public int Maxhp
        {
            get { return _maxhp; }
            set { _maxhp = value; }
        }

        protected int _maxratio = 50;
        public int Maxratio
        {
            get { return _maxratio; }
            set { _maxratio = value; }        
        }

        protected int _ratio;
        public int Ratio
        {
            get { return _ratio; }
            set { _ratio = value; }
        }
    #endregion

    #region  Initiation
        public HpBar(int hp,Vector2 posotion, Color color)
            :base(null, posotion)        
        {
            _hp = hp;
            _maxhp = hp;
            _ratio = _maxratio;
            _position = posotion;
            _color = color;           
        }
    #endregion

    #region Update & Draw
        public void Update(GameTime gametime, Vector2 position, int hp)                     
        {
            _hp = hp;
            _ratio = (int)(((float)_hp / (float)_maxhp) * _maxratio);
            _position = position;
        }

        public override void Draw(SpriteBatch spritebatch, GameTime gametime)
        {
            if (_texture == null)
            {
                _texture = new Texture2D(spritebatch.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
                UInt32[] pixel = { 0xFFFFFFFF }; // FFFFFF is White. 0xFF is Red, 0xFF0000 is Blue
                _texture.SetData<UInt32>(pixel, 0, _texture.Width * _texture.Height);
            }
             spritebatch.Draw(_texture, new Rectangle((int)_position.X, (int)_position.Y, _ratio, 10), _color);
        }
    #endregion
    }
}
